
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;


final class ViewAccountReport extends javax.swing.JInternalFrame {
    Object[][] tableObject=new Object[][]{};
    Systems systems=new Systems();
    String statementType="";
    String statementStartDate="";
    String statementEndDate="";
    String statementAccountName="";
    String statementAccountUnit="";
    String statementMerchantID="";
    String statementActivity="";
    String statementTransferActivityState="";
    final String statementMySQLAccountColumn="2";
    Thread viewAccountReportThread=new Thread();
    Thread viewAccountReportTitleThread=new Thread();
    String currentTitle="";
    /** Creates new form ViewCredit */
    public ViewAccountReport() {
        initComponents();
        //refreshTable();
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
    tableObject,
            new String [] {
                "S/N", "Date", "Account", "Credit Code", "Debit Code", "Amount", "Account Balance", "Currency", "Cash Flow Activity"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
        
        /* Execute submit thread */
        viewAccountReportThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                resetTransMonth();
                resetTransYear();
                resetEndMonth();
                resetEndYear();
                refreshTable();
            }
        });
        viewAccountReportTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountReportThread.isAlive())setProcessingTitle(viewAccountReportTitleThread);
                enableControls();
                System.out.println("viewaccountreportThread stopped runing.");
            }
        });
        viewAccountReportThread.start();
        viewAccountReportTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jAccountNameComboBox = new javax.swing.JComboBox();
        jMerchantIDComboBox = new javax.swing.JComboBox();
        startMonthComboBox = new javax.swing.JComboBox();
        startDayComboBox = new javax.swing.JComboBox();
        startYearComboBox = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jPreviewButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        endMonthComboBox = new javax.swing.JComboBox();
        endDayComboBox = new javax.swing.JComboBox();
        endYearComboBox = new javax.swing.JComboBox();
        jNameTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jAccountRadioButton = new javax.swing.JRadioButton();
        jMerchantRadioButton = new javax.swing.JRadioButton();
        jActivityRadioButton = new javax.swing.JRadioButton();
        jActivityComboBox = new javax.swing.JComboBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ViewAccountReport.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "S/N", "Date", "Account", "Credit Code", "Debit Code", "Amount", "Account Balance", "Currency", "Cash Flow Activity"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title8")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title5")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title16")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N
        jTable1.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(644, 40));

        jRefreshButton.setFont(resourceMap.getFont("jRefreshButton.font")); // NOI18N
        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setFont(resourceMap.getFont("jCancelButton.font")); // NOI18N
        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jAccountNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Account Name --" }));
        jAccountNameComboBox.setEnabled(false);
        jAccountNameComboBox.setName("jAccountNameComboBox"); // NOI18N

        jMerchantIDComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Merchant ID --" }));
        jMerchantIDComboBox.setEnabled(false);
        jMerchantIDComboBox.setName("jMerchantIDComboBox"); // NOI18N
        jMerchantIDComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMerchantIDComboBoxActionPerformed(evt);
            }
        });

        startMonthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Month --" }));
        startMonthComboBox.setName("startMonthComboBox"); // NOI18N
        startMonthComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startMonthComboBoxActionPerformed(evt);
            }
        });

        startDayComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Day --" }));
        startDayComboBox.setName("startDayComboBox"); // NOI18N

        startYearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Year --" }));
        startYearComboBox.setName("startYearComboBox"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jPreviewButton.setText(resourceMap.getString("jPreviewButton.text")); // NOI18N
        jPreviewButton.setName("jPreviewButton"); // NOI18N
        jPreviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPreviewButtonActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        endMonthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Month --" }));
        endMonthComboBox.setName("endMonthComboBox"); // NOI18N
        endMonthComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                endMonthComboBoxActionPerformed(evt);
            }
        });

        endDayComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Day --" }));
        endDayComboBox.setName("endDayComboBox"); // NOI18N

        endYearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Year --" }));
        endYearComboBox.setName("endYearComboBox"); // NOI18N

        jNameTextField.setEditable(false);
        jNameTextField.setName("jNameTextField"); // NOI18N
        jNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jNameTextFieldActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        buttonGroup1.add(jAccountRadioButton);
        jAccountRadioButton.setText(resourceMap.getString("jAccountRadioButton.text")); // NOI18N
        jAccountRadioButton.setName("jAccountRadioButton"); // NOI18N
        jAccountRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAccountRadioButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(jMerchantRadioButton);
        jMerchantRadioButton.setText(resourceMap.getString("jMerchantRadioButton.text")); // NOI18N
        jMerchantRadioButton.setName("jMerchantRadioButton"); // NOI18N
        jMerchantRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMerchantRadioButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(jActivityRadioButton);
        jActivityRadioButton.setText(resourceMap.getString("jActivityRadioButton.text")); // NOI18N
        jActivityRadioButton.setName("jActivityRadioButton"); // NOI18N
        jActivityRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jActivityRadioButtonActionPerformed(evt);
            }
        });

        jActivityComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Cash Flow Activity --", "Operating Activity", "Investing Activity", "Financing Activity", "---", "Transfer Activity" }));
        jActivityComboBox.setEnabled(false);
        jActivityComboBox.setName("jActivityComboBox"); // NOI18N
        jActivityComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jActivityComboBoxActionPerformed(evt);
            }
        });

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setText(resourceMap.getString("jCheckBox2.text")); // NOI18N
        jCheckBox2.setName("jCheckBox2"); // NOI18N
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jCheckBox3.setText(resourceMap.getString("jCheckBox3.text")); // NOI18N
        jCheckBox3.setName("jCheckBox3"); // NOI18N
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jCheckBox1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 304, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jPreviewButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                                .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jAccountRadioButton)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jMerchantRadioButton)
                                            .addComponent(jActivityRadioButton))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jActivityComboBox, 0, 364, Short.MAX_VALUE)
                                            .addComponent(jMerchantIDComboBox, 0, 364, Short.MAX_VALUE)
                                            .addComponent(jAccountNameComboBox, 0, 364, Short.MAX_VALUE)
                                            .addComponent(jCheckBox3))))
                                .addGap(43, 43, 43)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(182, 182, 182))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(startMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(startDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(startYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel9))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(endMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(endDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(endYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addComponent(jCheckBox2))
                .addGap(14, 14, 14))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jAccountNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jAccountRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jMerchantIDComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jMerchantRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jActivityRadioButton)
                            .addComponent(jActivityComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(startMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(startDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(startYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(endMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(endDayComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(endYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPreviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBox2)
                        .addGap(48, 48, 48))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed
        
        /* Execute refresh thread */
        viewAccountReportThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                refreshTable();
            }
        });
        viewAccountReportTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountReportThread.isAlive())setProcessingTitle(viewAccountReportTitleThread);
                enableControls();
                System.out.println("accountReportThread stopped runing.");
            }
        });
        viewAccountReportThread.start();
        viewAccountReportTitleThread.start();
    }//GEN-LAST:event_jRefreshButtonActionPerformed
                                        
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. View Account Report - Processing Request");
            thread.sleep(500);
            this.setTitle("::. View Account Report - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. View Account Report - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. View Account Report - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        
        if(viewAccountReportThread.isAlive())
        {
            try{
                viewAccountReportThread.stop();
                viewAccountReportTitleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle(currentTitle);
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed
    void reset()
    {
        /* Execute refresh thread */
        viewAccountReportThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                resetAccountName();
                resetMerchantName();
                resetTransMonth();
                resetTransYear();
                resetTransDay("");
                resetEndMonth();
                resetEndDay("");
                resetEndYear();
                jNameTextField.setText("");
                jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
                if(jCheckBox1.isSelected()){
                jCheckBox1.doClick();
                }
                if(jCheckBox2.isSelected()){
                jCheckBox2.doClick();
                }
                refreshTable();
            }
        });
        viewAccountReportTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountReportThread.isAlive())setProcessingTitle(viewAccountReportTitleThread);
                enableControls();
                System.out.println("accountReportThread stopped runing.");
            }
        });
        viewAccountReportThread.start();
        viewAccountReportTitleThread.start();
    }
    public void resetCombo()
    {
        resetAccountName();
        resetMerchantName();
        resetTransMonth();
        resetTransDay("");
        resetTransYear();
        resetEndMonth();
        resetEndDay("");
        resetEndYear();
        jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
    }
    public void resetAccountName()
    {
        String[] accountName=systems.getTableDataArray(OpenMSApp.Database_A,"Account",2);
        accountName[0]="-- Account Name --";
        jAccountNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(accountName));
        jAccountNameComboBox.setSelectedItem("-- Account Name --");
    }
    public void resetMerchantName()
    {
        String[] merchantName=systems.getTableDataArray(OpenMSApp.Database_A,"vwMerchant",2);
        merchantName[0]="-- Merchant Name --";
        jMerchantIDComboBox.setModel(new javax.swing.DefaultComboBoxModel(merchantName));
        resetMerchantID();
        jNameTextField.setText("");
    }
    public void disableAccountName()
    {
        jAccountNameComboBox.setEnabled(false);
    }
    public void disableMerchantName()
    {
        jMerchantIDComboBox.setEnabled(false);
    }
    private void startMonthComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startMonthComboBoxActionPerformed
        // TODO add your handling code here:
        String transMonth=startMonthComboBox.getSelectedItem().toString();

        if(transMonth.equals("-- Month --")) {
        } else {
            resetTransDay(transMonth);
        }
}//GEN-LAST:event_startMonthComboBoxActionPerformed

    public void resetTransYear()
    {
        String[] year=systems.getYears(1920);
        year[0]="-- Year --";
        startYearComboBox.setModel(new DefaultComboBoxModel(year));
    }
    public void resetTransMonth()
    {
        String[] month=systems.getMonthArray();
        month[0]="-- Month --";

        startMonthComboBox.setModel(new DefaultComboBoxModel(month));

    }
    public void resetTransDay(String Month)
    {
        String[] day={"-- Day --"};
        if(Month.isEmpty())
        {
            startDayComboBox.setModel(new DefaultComboBoxModel(day));
        }
        else
        {
            day=systems.getDays(Month);
            day[0]="-- Day --";
            startDayComboBox.setModel(new DefaultComboBoxModel(day));
        }

    }

    public void resetEndYear()
    {
        String[] year=systems.getYears(1920);
        year[0]="-- Year --";
        endYearComboBox.setModel(new DefaultComboBoxModel(year));
    }
    public void resetEndMonth()
    {
        String[] month=systems.getMonthArray();
        month[0]="-- Month --";

        endMonthComboBox.setModel(new DefaultComboBoxModel(month));

    }
    public void resetEndDay(String Month)
    {
        String[] day={"-- Day --"};
        if(Month.isEmpty())
        {
            endDayComboBox.setModel(new DefaultComboBoxModel(day));
        }
        else
        {
            day=systems.getDays(Month);
            day[0]="-- Day --";
            endDayComboBox.setModel(new DefaultComboBoxModel(day));
        }

    }

    public void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private void jPreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPreviewButtonActionPerformed

        /* Execute refresh thread */
        viewAccountReportThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                previewButton();
            }
        });
        viewAccountReportTitleThread=new Thread(new Runnable() {
            public void run() {
                while(viewAccountReportThread.isAlive())setProcessingTitle(viewAccountReportTitleThread);
                enableControls();
                System.out.println("accountReportThread stopped runing.");
            }
        });
        viewAccountReportThread.start();
        viewAccountReportTitleThread.start();
    }//GEN-LAST:event_jPreviewButtonActionPerformed
    private void previewButton()
    {
        //javax.swing.JInternalFrame printAccountStatement=new PrintAccountStatement(statementType,statementAccountName,statementAccountUnit,statementMerchantID,statementStartDate,statementEndDate);
        //this.getDesktopPane().add(printAccountStatement);
        //this.getDesktopPane().moveToFront(printAccountStatement);
        boolean statementOnly=jCheckBox3.isSelected();
        
        try
        {
            NoteWriter note=new NoteWriter();
            note.writeAccountStatement(statementType,statementAccountName,statementAccountUnit,statementMerchantID,statementActivity,statementTransferActivityState,statementStartDate,statementEndDate,statementOnly);
            
            if(OpenMSApp.d==null)
            {
                OpenMSApp.d=new NoteViewer("Preview Financial Statement",Configuration.accountStatementNoteURLPath);
                OpenMSApp.d.setVisible(true);
            }
            else if(OpenMSApp.d.isVisible()==false)
            {
                OpenMSApp.d=new NoteViewer("Preview Financial Statement",Configuration.accountStatementNoteURLPath);
                OpenMSApp.d.setVisible(true);                 
            }
            else
            {
                OpenMSApp.d.setTitle("Preview Financial Statement");
                OpenMSApp.d.doTas(OpenMSApp.d.FINANCIAL_STATEMENT_TABINDEX);
                OpenMSApp.d.transferFocus();                
            }
        }
        catch(Exception e)
        {
            System.out.println("Error while adding edit employee ! "+e);
        }
    }
    private void endMonthComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_endMonthComboBoxActionPerformed
        // TODO add your handling code here:
        String endMonth=endMonthComboBox.getSelectedItem().toString();

        if(endMonth.equals("-- Month --")) {
        } else {
            resetEndDay(endMonth);
        }
    }//GEN-LAST:event_endMonthComboBoxActionPerformed

    private void jNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNameTextFieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jNameTextFieldActionPerformed

    private void jMerchantIDComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMerchantIDComboBoxActionPerformed
        // TODO add your handling code here:
        String merchantID=jMerchantIDComboBox.getSelectedItem().toString();
        if(merchantID.equals("-- Merchant ID --"))
        {
            resetMerchantID();
        }
        else
        {
            jNameTextField.setText(systems.getValue(OpenMSApp.Database_A, "Select * from vwMerchant where cMerchantID = '"+merchantID+"'", "vName"));
        }
    }//GEN-LAST:event_jMerchantIDComboBoxActionPerformed

    private void jAccountRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAccountRadioButtonActionPerformed
        // TODO add your handling code here:
        if(jAccountRadioButton.isSelected())
        {
            jMerchantIDComboBox.setEnabled(false);
            jActivityComboBox.setEnabled(false);
            jAccountNameComboBox.setEnabled(true);
        }
        else
        {
            jAccountNameComboBox.setEnabled(false);
            jAccountNameComboBox.setSelectedItem("-- Account Name --");
        }
        resetAccountName();
        resetMerchantName();
        jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
    }//GEN-LAST:event_jAccountRadioButtonActionPerformed

    private void jMerchantRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMerchantRadioButtonActionPerformed
        // TODO add your handling code here:
        if(jMerchantRadioButton.isSelected())
        {
            jMerchantIDComboBox.setEnabled(true);
            jAccountNameComboBox.setEnabled(false);
            jActivityComboBox.setEnabled(false);
        }
        else
        {
            jMerchantIDComboBox.setEnabled(false);
            jMerchantIDComboBox.setSelectedItem("-- Merchant ID --");
        }
        resetMerchantName();
        resetAccountName();
        jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
    }//GEN-LAST:event_jMerchantRadioButtonActionPerformed

    private void jActivityRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jActivityRadioButtonActionPerformed
        // TODO add your handling code here:
        if(jActivityRadioButton.isSelected())
        {
            jActivityComboBox.setEnabled(true);
            jMerchantIDComboBox.setEnabled(false);
            jAccountNameComboBox.setEnabled(false);
        }
        else
        {
            jActivityComboBox.setEnabled(false);
            jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
        }
        resetMerchantName();
        resetAccountName();
        jActivityComboBox.setSelectedItem("-- Cash Flow Activity --");
    }//GEN-LAST:event_jActivityRadioButtonActionPerformed

    private void jActivityComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jActivityComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jActivityComboBoxActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox2ActionPerformed

private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCheckBox3ActionPerformed
    public void resetMerchantID()
    {
        String[] merchant=systems.getTableDataArray(OpenMSApp.Database_A,"vwMerchant",1);
        merchant[0]="-- Merchant ID --";

        jMerchantIDComboBox.setModel(new DefaultComboBoxModel(merchant));
        jNameTextField.setText("");
    }
    public String getTransactionDate(String creditCode,String debitCode)
    {
        String value="";
        if(creditCode!="N/A")
        {
           value=systems.getValue(OpenMSApp.Database_A, "Select dCreditPostDate from creditOrder where cCreditCode='"+creditCode+"'", "dCreditPostDate");
           //System.out.println("Date cred value="+value);
           if(value.isEmpty())
           value=systems.getValue(OpenMSApp.Database_A, "Select dReverseDate from debitOrder where cReverseCode='"+creditCode+"'", "dReverseDate");
        }
        if(debitCode!="N/A")
        {
           value=systems.getValue(OpenMSApp.Database_A, "Select dDebitPostDate from debitOrder where cDebitCode='"+debitCode+"'", "dDebitPostDate");
           //System.out.println("Date deb value="+value);
           if(value.isEmpty())
           value=systems.getValue(OpenMSApp.Database_A, "Select dReverseDate from creditOrder where cReverseCode='"+debitCode+"'", "dReverseDate");
        }
        return value;
    }
    private boolean isDateChoosen()
    {
        boolean dateChoosen=false;
        if(!startMonthComboBox.getSelectedItem().equals("-- Month --"))
        {
            dateChoosen=true;
        }
        if(!startDayComboBox.getSelectedItem().equals("-- Day --"))
        {
            dateChoosen=true;
        }
        if(!startYearComboBox.getSelectedItem().equals("-- Year --"))
        {
            dateChoosen=true;
        }
        if(!endMonthComboBox.getSelectedItem().equals("-- Month --"))
        {
            dateChoosen=true;
        }
        if(!endDayComboBox.getSelectedItem().equals("-- Day --"))
        {
            dateChoosen=true;
        }
        if(!endYearComboBox.getSelectedItem().equals("-- Year --"))
        {
            dateChoosen=true;
        }
        return dateChoosen;
    }
    private void disableControls()
    {
        jPreviewButton.setEnabled(false);
        jRefreshButton.setEnabled(false);
        jAccountRadioButton.setEnabled(false);
        jMerchantRadioButton.setEnabled(false);
        jActivityRadioButton.setEnabled(false);
        jAccountNameComboBox.setEnabled(false);
        jMerchantIDComboBox.setEnabled(false);
        jActivityComboBox.setEnabled(false);
        jCheckBox1.setEnabled(false);
        jCheckBox2.setEnabled(false);
        jCheckBox3.setEnabled(false);
        startMonthComboBox.setEnabled(false);
        startDayComboBox.setEnabled(false);
        startYearComboBox.setEnabled(false);
        endMonthComboBox.setEnabled(false);
        endDayComboBox.setEnabled(false);
        endYearComboBox.setEnabled(false);
    }
    private void enableControls()
    {
        jPreviewButton.setEnabled(true);
        jRefreshButton.setEnabled(true);
        jAccountRadioButton.setEnabled(true);
        jMerchantRadioButton.setEnabled(true);
        jActivityRadioButton.setEnabled(true);
        
        if(jAccountRadioButton.isSelected())
        {
            jMerchantIDComboBox.setEnabled(false);
            jActivityComboBox.setEnabled(false);
            jAccountNameComboBox.setEnabled(true);
        }
        if(jMerchantRadioButton.isSelected())
        {
            jMerchantIDComboBox.setEnabled(true);
            jAccountNameComboBox.setEnabled(false);
            jActivityComboBox.setEnabled(false);
        }
        if(jActivityRadioButton.isSelected())
        {
            jActivityComboBox.setEnabled(true);
            jMerchantIDComboBox.setEnabled(false);
            jAccountNameComboBox.setEnabled(false);
        }
        
        jCheckBox1.setEnabled(true);
        jCheckBox2.setEnabled(true);
        jCheckBox3.setEnabled(true);
        startMonthComboBox.setEnabled(true);
        startDayComboBox.setEnabled(true);
        startYearComboBox.setEnabled(true);
        endMonthComboBox.setEnabled(true);
        endDayComboBox.setEnabled(true);
        endYearComboBox.setEnabled(true);
        this.setTitle(currentTitle);
    }
    synchronized void refreshTable()
    {
        String entryCode[]={};
        String accountCode[]={};
        String creditCode[]={};
        String debitCode[]={};
        String amount[]={};
        String accountBalance[]={};
        String accountName_A=String.valueOf(jAccountNameComboBox.getSelectedItem());
        String merchantID_A=String.valueOf(jMerchantIDComboBox.getSelectedItem());
        String activity_A=String.valueOf(jActivityComboBox.getSelectedItem());
        String useDate="N";
        String startDate="";
        String endDate="";
        String activity="";

        if(jCheckBox1.isSelected()) {
            statementTransferActivityState=" and cActivity != 'Transfer Activity' ";
        } else {
            statementTransferActivityState="";
        }

        if(jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("Financing Activity")||jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("Investing Activity")||jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("Operating Activity")||jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("Transfering Activity")){
            statementTransferActivityState="";
            if(jCheckBox1.isSelected())
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"'EXCLUDE TRANSFERING ACTIVITY' WILL BE IGNORED","WARNING !",JOptionPane.WARNING_MESSAGE);

            }
        }

        if(isDateChoosen()==true)
            {
            if(startMonthComboBox.getSelectedItem().equals("-- Month --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report Start Date's Month ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(startDayComboBox.getSelectedItem().equals("-- Day --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report Start Date's Day ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(startYearComboBox.getSelectedItem().equals("-- Year --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report Start Date's Year ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(endMonthComboBox.getSelectedItem().equals("-- Month --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report End Date's Month ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(endDayComboBox.getSelectedItem().equals("-- Day --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report End Date's Day ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
            if(endYearComboBox.getSelectedItem().equals("-- Year --"))
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Report End Date's Year ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
        useDate="Y";
        startDate=new String(String.valueOf(startYearComboBox.getSelectedItem()).trim()+"-"+systems.getMonthDigit(String.valueOf(startMonthComboBox.getSelectedItem()).trim())+"-"+
                            String.valueOf(startDayComboBox.getSelectedItem()).trim());
        endDate=new String(String.valueOf(endYearComboBox.getSelectedItem()).trim()+"-"+systems.getMonthDigit(String.valueOf(endMonthComboBox.getSelectedItem()).trim())+"-"+
                            String.valueOf(endDayComboBox.getSelectedItem()).trim());
        statementStartDate=startDate;
        statementEndDate=endDate;
        }
        
        if(accountName_A.equalsIgnoreCase("-- Account Name --")==false && useDate=="N")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::ACCOUNT, PERIOD::ALL]");
            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::ACCOUNT, PERIOD::ALL]";
            //System.out.println("sort by account , date=n");

            statementType="ACCOUNT_N";
            statementAccountName=accountName_A;
//            statementAccountUnit=systems.getValue(OpenMSApp.Database_A, "Select * from Account  Where vAccountName='"+accountName_A+"'","vAccountUnit");
//            String accountCode_A=systems.getValue(OpenMSApp.Database_A, "Select * from Account  Where vAccountName='"+accountName_A+"'","cAccountCode");
//            entryCode=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+"order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+" order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+" order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"'"+statementTransferActivityState+" order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+"order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+"order by dOrderDate",6);
            
            String holder[]=systems.getValue(OpenMSApp.Database_A, "Select * from Account  Where vAccountName='"+accountName_A+"'","vAccountUnit","cAccountCode");
            statementAccountUnit=holder[0];
            String accountCode_A=holder[1];
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A, "select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode or pay.cCreditCode=debitorder.cReversecode Where pay.cAccountCode='"+accountCode_A+"' "+statementTransferActivityState+"order by dOrderDate", 1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(merchantID_A.equalsIgnoreCase("-- Merchant ID --")==false && useDate=="N")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::MERCHANT, PERIOD::ALL]");
            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::MERCHANT, PERIOD::ALL]";
            statementType="MERCHANT_N";
            statementMerchantID=jMerchantIDComboBox.getSelectedItem().toString().trim();

//System.out.println("sort by merchant , date=n");
//            entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+"order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate",6);
        
        
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode or pay.cDebitCode=Creditorder.cReversecode Where creditOrder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode or pay.cCreditCode=debitorder.cReversecode Where debitorder.cMerchantID='"+merchantID_A+"' "+statementTransferActivityState+" order by dOrderDate", 1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(accountName_A.equalsIgnoreCase("-- Account Name --")==false && useDate=="Y")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::ACCOUNT, PERIOD::"+startDate+" TO "+endDate+"]");

            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::ACCOUNT, PERIOD::"+startDate+" TO "+endDate+"]";
            //System.out.println("sort by account , date=y");
            statementType="ACCOUNT_Y";
            statementAccountName=accountName_A;
//            statementAccountUnit=systems.getValue(OpenMSApp.Database_A, "Select * from Account  Where vAccountName='"+accountName_A+"'","vAccountUnit");
//
//            String accountCode_A=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where vAccountName='"+accountName_A+"'","cAccountCode");
//            entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate ",6);
        
        
            String holder[]=systems.getValue(OpenMSApp.Database_A, "Select * from Account  Where vAccountName='"+accountName_A+"'","vAccountUnit","cAccountCode");
            statementAccountUnit=holder[0];
            String accountCode_A=holder[1];
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode or pay.cCreditCode=debitorder.cReversecode Where pay.cAccountCode='"+accountCode_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode or pay.cCreditCode=debitorder.cReversecode Where pay.cAccountCode='"+accountCode_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(merchantID_A.equalsIgnoreCase("-- Merchant ID --")==false && useDate=="Y")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::MERCHANT, PERIOD::"+startDate+" TO "+endDate+"]");

            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::MERCHANT, PERIOD::"+startDate+" TO "+endDate+"]";
            //System.out.println("sort by merchant , date=y");
            statementType="MERCHANT_Y";
            statementMerchantID=jMerchantIDComboBox.getSelectedItem().toString().trim();

//            entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59'"+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate",6);
        
        
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode Where creditOrder.cMerchantID='"+merchantID_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode Where debitOrder.cMerchantID='"+merchantID_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(activity_A.equalsIgnoreCase("-- Cash Flow Activity --")==false && useDate=="N")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::CASH FLOWS ACTIVITY, PERIOD::ALL]");
            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::CASH FLOWS ACTIVITY, PERIOD::ALL]";
            statementType="ACTIVITY_N";
            statementActivity=jActivityComboBox.getSelectedItem().toString().trim();

//System.out.println("sort by activity , date=n");
//            entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate",6);
        
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode Where creditOrder.cActivity='"+activity_A+"' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode or pay.cCreditCode=debitorder.cReversecode  Where debitorder.cActivity='"+activity_A+"' "+statementTransferActivityState+"order by dOrderDate",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(activity_A.equalsIgnoreCase("-- Cash Flow Activity --")==false && useDate=="Y")
        {
            this.setTitle("::. View Account Report [SORT::SINGLE, ENTITY::CASH FLOWS ACTIVITY, PERIOD::"+startDate+" TO "+endDate+"]");
            
            currentTitle="::. View Account Report [SORT::SINGLE, ENTITY::CASH FLOWS ACTIVITY, PERIOD::"+startDate+" TO "+endDate+"]";
//System.out.println("sort by activity , date=y");
            statementType="ACTIVITY_Y";
            statementActivity=activity_A;

//            entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 1);
//            accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59'"+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 2);
//            creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 3);
//            debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder  on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 4);
//            amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder  on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+"  23:59:59' "+statementTransferActivityState+"order by dOrderDate", 5);
//            accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by dOrderDate ",6);
        
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode Where creditorder.cActivity='"+activity_A+"' AND creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode Where debitorder.cActivity='"+activity_A+"' AND debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by dOrderDate ",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
        }
        if(merchantID_A.equalsIgnoreCase("-- Merchant ID --")==true && activity_A.equalsIgnoreCase("-- Cash Flow Activity --") && accountName_A.equalsIgnoreCase("-- Account Name --")==true && useDate=="Y")
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::NONE, PERIOD::"+startDate+" TO "+endDate+"]";
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::NONE, PERIOD::"+startDate+" TO "+endDate+"]");
//System.out.println("sort by full , date=y");
            statementType="FULL_Y";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by dOrderDate",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode or pay.cCreditCode=debitorder.cReversecode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by dOrderDate,dReverseDate",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        if(merchantID_A.equalsIgnoreCase("-- Merchant ID --")==true && activity_A.equalsIgnoreCase("-- Cash Flow Activity --") && accountName_A.equalsIgnoreCase("-- Account Name --")==true && useDate=="N")
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::NONE, PERIOD::ALL]";
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::NONE, PERIOD::ALL]");
//System.out.println("sort by full , date=n");
            statementType="FULL_N";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by dOrderDate", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by dOrderDate", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by dOrderDate",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by dOrderDate", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by dOrderDate", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by dOrderDate", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cPayCode",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        /*
            if(merchantID_A.equalsIgnoreCase("-- Select --")==true && activity_A.equalsIgnoreCase("-- Select --") && accountName_A.equalsIgnoreCase("-- Select --")==true && useDate=="N")
            {
System.out.println("sort by full , date=n");
            statementType="FULL_N";
             entryCode=systems.getTableDataArrayNum(OpenMSApp.Database_A, "pay", 1);
             accountCode=systems.getTableDataArrayNum(OpenMSApp.Database_A, "Pay", 2);
             creditCode=systems.getTableDataArrayNum(OpenMSApp.Database_A, "Pay",3 );
             debitCode=systems.getTableDataArrayNum(OpenMSApp.Database_A, "Pay", 4);
             amount=systems.getTableDataArrayNum(OpenMSApp.Database_A, "Pay", 5);
             accountBalance=systems.getTableDataArrayNum(OpenMSApp.Database_A, "Pay", 6);
            }
*/
        if(jMerchantRadioButton.isSelected() && jMerchantIDComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Merchant ID --") && useDate=="Y" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::MERCHANT, PERIOD::"+startDate+" TO "+endDate+"]";
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::MERCHANT, PERIOD::"+startDate+" TO "+endDate+"]");
//System.out.println("sort by full, Merchant , date=y");
            statementType="FULL_MERCHANT_Y";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by cMerchantID",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cMerchantID",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        if(jMerchantRadioButton.isSelected() && jMerchantIDComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Merchant ID --") && useDate=="N" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::MERCHANT, PERIOD::ALL]";            
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::MERCHANT, PERIOD::ALL]");
//System.out.println("sort by full,Merchant , date=n");
            statementType="FULL_MERCHANT_N";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by cMerchantID",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID", 6);
            
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cMerchantID",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        /*

         */
        if(jAccountRadioButton.isSelected() && jAccountNameComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Account Name --") && useDate=="Y" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::ACCOUNT, PERIOD::"+startDate+" TO "+endDate+"]";
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::ACCOUNT, PERIOD::"+startDate+" TO "+endDate+"]");
//System.out.println("sort by full,Account , date=y");
            statementType="FULL_ACCOUNT_Y";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"", 6);
            
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by "+statementMySQLAccountColumn+"",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        if(jAccountRadioButton.isSelected() && jAccountNameComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Account Name --") && useDate=="N" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::ACCOUNT, PERIOD::ALL]";
           
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::ACCOUNT, PERIOD::ALL]");
//System.out.println("sort by full,Account , date=n");
            statementType="FULL_ACCOUNT_N";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cCreditCode=debitorder.cReversecode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by "+statementMySQLAccountColumn+"",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }

        /*

         */
        if(jActivityRadioButton.isSelected() && jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Cash Flow Activity --") && useDate=="Y" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::CASH FLOWS ACTIVITY, PERIOD::"+startDate+" TO "+endDate+"]";
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::CASH FLOWS ACTIVITY, PERIOD::"+startDate+" TO "+endDate+"]");
//System.out.println("sort by full,Activity , date=y");
            statementType="FULL_ACTIVITY_Y";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+" order by cActivity",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate BETWEEN '"+startDate+" 00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate BETWEEN '"+startDate+"  00:00:00' AND '"+endDate+" 23:59:59' "+statementTransferActivityState+"order by cActivity",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }
        if(jActivityRadioButton.isSelected() && jActivityComboBox.getSelectedItem().toString().equalsIgnoreCase("-- Cash Flow Activity --") && useDate=="N" && jCheckBox2.isSelected())
            {
            currentTitle="::. View Account Report [SORT::FULL, GROUPING ENTITY::CASH FLOWS ACTIVITY, PERIOD::ALL]";            
            this.setTitle("::. View Account Report [SORT::FULL, GROUPING ENTITY::CASH FLOWS ACTIVITY, PERIOD::ALL]");
//System.out.println("sort by full,Activity,date=n");
            statementType="FULL_ACTIVITY_N";
//             entryCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity", 1);
//             accountCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity", 2);
//             creditCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+" order by cActivity",3 );
//             debitCode=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity", 4);
//             amount=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL' "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity", 5);
//             accountBalance=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
//" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity", 6);
            
            String colHolder[][]=systems.getColumn(OpenMSApp.Database_A,"select * from pay join creditOrder on pay.ccreditcode=creditorder.ccreditcode  or pay.cDebitCode=creditorder.cReversecode WHERE creditOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+
" union select * from pay join debitorder on pay.cdebitCode=debitorder.cdebitCode  or pay.cCreditCode=debitorder.cReversecode WHERE debitOrder.dOrderDate  != 'NULL'  "+statementTransferActivityState+"order by cActivity",1,2,3,4,5,6);
            entryCode=colHolder[0];
            accountCode=colHolder[1];
            creditCode=colHolder[2];
            debitCode=colHolder[3];
            amount=colHolder[4];
            accountBalance=colHolder[5];
            }

        int x=0;
        int z=debitCode.length;
        //System.out.println("z====="+z);
        int y=entryCode.length;

        tableObject=new Object[y][9];

        while(x<y)
        {
            if(creditCode[x]==null)
            {
                creditCode[x]="N/A";
                activity=systems.getValue(OpenMSApp.Database_A, "Select cActivity from debitorder where cDebitCode='"+debitCode[x]+"'","cActivity");
                if(activity.isEmpty())
                activity=systems.getValue(OpenMSApp.Database_A, "Select cActivity from creditorder where cReverseCode='"+debitCode[x]+"'","cActivity");
            }
            if(debitCode[x]==null)
            {
                debitCode[x]="N/A";
                activity=systems.getValue(OpenMSApp.Database_A, "Select cActivity from creditorder where cCreditCode='"+creditCode[x]+"'","cActivity");
                if(activity.isEmpty())
                activity=systems.getValue(OpenMSApp.Database_A, "Select cActivity from debitorder where cReverseCode='"+creditCode[x]+"'","cActivity");
            }
//            activity=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+accountCode[x]+"'", "cActivity");
//            
//            String accountName=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where cAccountCode='"+accountCode[x]+"'", "vAccountName");
//            String accountCurrency=systems.getValue(OpenMSApp.Database_A, "Select * from Account Where cAccountCode='"+accountCode[x]+"'", "vAccountUnit");
            
            String[] holder=systems.getValue(OpenMSApp.Database_A, "Select * from Account where cAccountCode='"+accountCode[x]+"'", "cActivity", "vAccountName", "vAccountUnit");
            
            //activity=holder[0];
            String accountName=holder[1];
            String accountCurrency=holder[2];
            tableObject[x][0]=x+1;
            tableObject[x][1]=getTransactionDate(creditCode[x].trim(),debitCode[x].trim()).trim();
            tableObject[x][2]=accountName;
            tableObject[x][3]=creditCode[x].trim();
            tableObject[x][4]=debitCode[x].trim();
            try
            {
                tableObject[x][5]=systems.converToRealMoneyFormat(amount[x].trim());
            }
            catch(Exception e)
            {
                tableObject[x][5]="Er!M1C01K0";
            }
            try
            {
                tableObject[x][6]=systems.converToRealMoneyFormat(accountBalance[x].trim());
            }
            catch(Exception e)
            {
                tableObject[x][6]="Er!M1C01K0";
            }
            tableObject[x][7]=accountCurrency;
            tableObject[x][8]=activity;
            systems.freeHeap();
            x+=1;
            if(x==y){break;}
       }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
    tableObject,
            new String [] {
                "S/N", "Date", "Account", "Credit Code", "Debit Code", "Amount", "Account Balance", "Currency", "Cash Flow Activity"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox endDayComboBox;
    private javax.swing.JComboBox endMonthComboBox;
    private javax.swing.JComboBox endYearComboBox;
    private javax.swing.JComboBox jAccountNameComboBox;
    private javax.swing.JRadioButton jAccountRadioButton;
    private javax.swing.JComboBox jActivityComboBox;
    private javax.swing.JRadioButton jActivityRadioButton;
    private javax.swing.JButton jCancelButton;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox jMerchantIDComboBox;
    private javax.swing.JRadioButton jMerchantRadioButton;
    private javax.swing.JTextField jNameTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jPreviewButton;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JComboBox startDayComboBox;
    private javax.swing.JComboBox startMonthComboBox;
    private javax.swing.JComboBox startYearComboBox;
    // End of variables declaration//GEN-END:variables

}
